<?
// $a ='1434538404';
// echo date('Y-m-d',$a);exit;
/*
$time= time();
$sign = MD5('_pid=18500399115&_ts='.$time.'&format=xml&pageindex=1&pagesize=587b3b679712399af25c2e98d');
$url='http://debug.open.piaoduoduo.cn/PlatForm/API?method=Agent_GetProductList&_pid=18500399115&_ts='.$time.'&format=xml&pageindex=1&pagesize=5&_sign='.$sign;
$r=file_get_contents($url);
var_dump($r);exit;
*/
$txt=file_get_contents('php://input');
logfile("-----------------------------".date('Y-m-d H:i:s')."-----------------------------------",'qunar_coop_log.txt');
logfile($txt,'qunar_coop_log.txt');
$APPROVE = $_REQUEST['applyOrder'];
$supplierIdentity =$_REQUEST['supplierIdentity'];
$nowdate = $_REQUEST['nowdate'];
$ordern = $_REQUEST['ordern'];
$refundSeq = $_REQUEST['refundSeq'];
$tnum = $_REQUEST['tnum'];
$rnum = $_REQUEST['rnum'];
$signkey = $_REQUEST['signkey'];
// print_r($_REQUEST);exit;
//供应商通知用户申请退款结果
$noticeOrderRefundApproveResult=<<<XML
<?xml version="1.0" encoding="UTF-8"?>
<request xsi:schemaLocation="http://piao.qunar.com/2013/QMenpiaoRequestSchema QMRequestDataSchema-2.0.1.xsd" 

xmlns="http://piao.qunar.com/2013/QMenpiaoRequestSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<header>
		<application>Qunar.Menpiao.Agent</application>
		<processor>SupplierDataExchangeProcessor</processor>
		<version>v2.0.1</version>
		<bodyType>NoticeOrderRefundApproveResultRequestBody</bodyType>
		<createUser>$supplierIdentity</createUser>
		<createTime>$nowdate</createTime>
		<supplierIdentity>$supplierIdentity</supplierIdentity>
	</header>
	<body xsi:type="NoticeOrderRefundApproveResultRequestBody">
		<orderInfo>
			<partnerorderId>$ordern</partnerorderId>
			<refundSeq>$refundSeq</refundSeq>
			<orderQuantity>$tnum</orderQuantity>
			<refundQuantity>$rnum</refundQuantity>
			<refundJudgeMark></refundJudgeMark>
			<refundResult>$APPROVE</refundResult>
		</orderInfo>
	</body>
</request>			
XML;
			// echo $noticeOrderRefundApproveResult;exit;
			$bstr=base64_encode($noticeOrderRefundApproveResult);
			$signeda=strtoupper(md5($signkey.$bstr));
			$arr=array('data'=>$bstr,'signed'=>$signeda,'securityType'=>'MD5');
			$post_arr = json_encode($arr);
			// sleep(10);
			lqunar_post('noticeOrderRefundApproveResult',$post_arr);
			

function lqunar_post($aq, $cq){
	$post_data = array(); 
	$post_data['method'] = $aq; 
	$post_data['requestParam'] = $cq; 
	// $url='http://piaoagentdev.qunar.com/api/external/supplierServiceV2.qunar';
	$url='http://piaofutong.tunnel.mobi/api/external/supplierServiceV2.qunar';
	$o=""; 
	foreach ($post_data as $k=>$v){ 
		$o.= "$k=".urlencode($v)."&"; 
	} 
	$post_data=substr($o,0,-1); 

	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_POST, 1); 
	curl_setopt($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_URL,$url); 
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
	curl_exec($ch);
	return $ch;
}
function logfile($txt,$path){
	$fp = fopen($path,"a");
	flock($fp, LOCK_EX) ;
	fwrite($fp,$txt."\n");
	flock($fp, LOCK_UN);
	fclose($fp); 
}
?>